import asyncio
import sys
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def main():
    print("Starting Host...")
    
    # 设置服务器参数
    server_params = StdioServerParameters(
        command=sys.executable,  # 使用当前 Python 解释器
        args=["./server.py"],
        env=None
    )

    # 使用 async with 来正确处理异步上下文管理器
    # 创建 stdio client
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await asyncio.wait_for(session.initialize(), timeout=10)

            result = await asyncio.wait_for(session.call_tool("hello"), timeout=10)
            print(f"Tool call result: {result.content[0].text}")

if __name__ == "__main__":
    asyncio.run(main())